package integration

import (
	upb "gitee.com/micro-services/protocol/user/server"
	vpb "gitee.com/micro-services/protocol/verify/server"
	"github.com/micro/go-micro/v2"
	"sync"
)

var microInstance *ProxyManger
var microOnce sync.Once

type ProxyManger struct {
	UserServiceProxy    upb.AdminUserService
	CaptchaServiceProxy vpb.CaptchaServerService
	EmailServiceProxy   vpb.EmailServerService
}

func GetProxyManger() *ProxyManger {
	microOnce.Do(func() {
		microInstance = &ProxyManger{}
		microInstance.init()
	})
	return microInstance
}

func (m *ProxyManger) init() {
	service := micro.NewService()
	m.UserServiceProxy = upb.NewAdminUserService("go.micro.user.server", service.Client())
	m.CaptchaServiceProxy = vpb.NewCaptchaServerService("go.micro.verify.server", service.Client())
	m.EmailServiceProxy = vpb.NewEmailServerService("go.micro.verify.server", service.Client())
}
